package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.domain.SuccessCode;
import com.atguigu.jxc.entity.Customer;
import com.atguigu.jxc.entity.Supplier;
import com.atguigu.jxc.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RequestMapping("/customer")
@RestController
public class CustomerController {
    @Autowired
    CustomerService customerService;

    @PostMapping("/list")
    public Map<String ,Object> findPage(Integer page, Integer rows, String  customerName){
        Map<String ,Object> map=customerService.findPageByName(page,rows,customerName);
        return map;
    }
    @PostMapping("/save")
    public ServiceVO saveOrUpdate(@RequestParam(value = "customerId",required = false) Integer customerId,
                                  Customer customer){
        customerService.saveOrUpdate(customerId,customer);
        return new ServiceVO(SuccessCode.SUCCESS_CODE,SuccessCode.SUCCESS_MESS);
    }
    @PostMapping("/delete")
    public ServiceVO delete(String ids){
        customerService.delete(ids);
        return new ServiceVO(SuccessCode.SUCCESS_CODE,SuccessCode.SUCCESS_MESS);
    }


}
